package com.jiangkang.lottery.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeUtil {
	public static String pattern = "yyyyMMdd";

	public static SimpleDateFormat formatter = new SimpleDateFormat(pattern);

	private static SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	private static SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd");

	public static String millis2DateTime(long millis) {
		Date date = new Date();
		date.setTime(millis);
		return formatter1.format(date);
	}
	
	public static String millis2DateTime2(long millis) {
		Date date = new Date();
		date.setTime(millis);
		return formatter2.format(date);
	}

	public static String getNowDateString() {
		String dateString = formatter.format(new Date());
		return dateString;
	}
	
	public static String getNowDateString1() {
		String dateString = formatter1.format(new Date());
		return dateString;
	}

	public static String getNowDateString2() {
		String dateString = formatter2.format(new Date());
		return dateString;
	}
	
	public static Date getNowDate1() {
		try {
			return formatter1.parse(formatter1.format(new Date()));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static Date getNowDate2() {
		try {
			return formatter2.parse(formatter2.format(new Date()));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getDateString1(Date date) {
		String dateString = formatter1.format(date);
		return dateString;
	}
	
	public static String getDateString2(Date date) {
		String dateString = formatter2.format(date);
		return dateString;
	}
	
	public static Date getNowDate() {
		return new Date(System.currentTimeMillis());
	}
	
	public static Date transForDate2(String date) {
		try {
			return formatter2.parse(date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public static Date transForDate(Long ms) {
		if (ms == null) {
			ms = (long) 0;
		}
		Date temp = null;
		String str = formatter1.format(ms);
		try {
			temp = formatter1.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return temp;
	}
	
	public static Date transForDate2(Long ms) {
		if (ms == null) {
			ms = (long) 0;
		}
		Date temp = null;
		String str = formatter2.format(ms);
		try {
			temp = formatter2.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return temp;
	}
	

//	public static int getTimespan(Date fromDate) {
//		 return Days.daysBetween(
//		           new LocalDate(fromDate.getTime()), 
//		           new LocalDate(System.currentTimeMillis())).getDays();
//	}
//	
//	public static int getTimespan(Date fromDate,Date toDate) {
//		 return Days.daysBetween(
//		           new LocalDate(fromDate.getTime()), 
//		           new LocalDate(toDate.getTime())).getDays();
//	}
	
	public static void main(String[] args) {
		// System.out.println(String.valueOf(System.currentTimeMillis())+"\n目标：3\n已完成：2\n还需要3位小伙伴");
//		System.out.println(getTimespan("2018-1-1"));
//		System.out.println(getDateString1(transForDate(System.currentTimeMillis())));
	}
}
